<template>
<el-row>
  <el-form label-width="110px" :model="form" :disabled="show" :class="show ? 'disabled' : ''" size="small">
    <el-col :xl="8" :lg="12" :md="12" :sm="24" :xs="24">
      <el-form-item label="公众号APPID：">
        <el-input class="w240" v-model="form.weixin_appid"></el-input>
      </el-form-item>
    </el-col>
    <el-col :xl="16" :lg="12" :md="12" :sm="24" :xs="24">
      <el-form-item label="公众号SECRET：">
        <el-input class="w240" v-model="form.weixin_secret"></el-input>
      </el-form-item>
    </el-col>
  </el-form>
  <el-col :span="23" :offset="1">
    <el-button v-if="!show" type="primary" size="small" @click="handleClickSubmit" :loading="loading" :disabled="disabled">提交审核</el-button>
    <el-button v-if="!show" type="info" size="small" @click="show = true" >取消编辑</el-button>
    <el-button v-if="show" type="primary" size="small" @click="show = false" >编辑资料</el-button>
  </el-col>
</el-row>
</template>
  

<script>
import { mapGetters } from 'vuex'
import { merchantWechatUpdate } from '@/api/shop'

export default {
  data() {
    return {
      show: true,
      loading: false,
      disabled: false,
      form: {
        weixin_secret: '',
        weixin_appid: ''
      }
    }
  },
  computed: {
    ...mapGetters([
      'id'
    ])
  },
  props: {
    merchantNum: {
      required: true,
      type: String
    },
    data: {
      required: true,
      type: Object
    }
  },
  methods: {
    handleClickSubmit() {
      this.loading = true
      merchantWechatUpdate(this.merchantNum, this.id, this.form).then(res => {
        if (res.data.errorCode === 0) {
          this.$message.success('微信公众号资料提交成功，请耐心等待审核~')
          this.loading = false
          this.disabled = true
          this.show = true
          this.$emit('update')
        } else {
          this.$message.error(res.data.errorMsg)
        }
      })
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.form.weixin_secret = this.data.weixin_secret
      this.form.weixin_appid = this.data.weixin_appid
    })
  }
}
</script>